$(function () {

    iniList();
    bindClick();

})

function iniList() {
    $("#resourceList").datagrid({
        url:'/admin/resource/query',
        method:'GET',
        pagination:true,
        rownumbers: true,
        local:"zh_CN",
        pageNumber:1,
        pageSize:10,
        singleSelect:true,
        queryParams: {
        },
        columns:[[
            {field:'id',title:'ID',width:50},
            {field:'resourceName',title:'资源名称',width:150},
            {field:'resourceUrl',title:'资源url',width:200},
            {field:'createTime',title:'创建时间',width:150,
                formatter: function(value,row,index){
                    return Kit.simpleFmtDate(value,"yyyy-MM-dd hh:mm:ss");
                }
            },
            {field:'updateTime',title:'上次更新时间',width:150,
                formatter: function(value,row,index){
                    return Kit.simpleFmtDate(value,"yyyy-MM-dd hh:mm:ss");
                }
            },
            {field:'parentId',title:'父级Id',width:50}

        ]],
        loadFilter: function(data){
            if (data.code == '0000'){
                return data.retData.rows;
            } else {
                return [];
            }
        },
        onBeforeLoad: function (param) {

        }
    });
}



function bindClick() {
    $("#addBtn").on("click",function (){
        $('#win').window({
            width:600,
            height:400,
            modal:true,
            title:"资源增加",
            href:"/view/biz/resource/addResource.html"
        });
    })

    $("#editBtn").on("click",function (){
        $('#win').window({
            width:600,
            height:400,
            modal:true,
            title:"资源编辑",
            href:"/view/biz/resource/editResource.html"
        });
    })

    $("#delBtn").on("click",function (){

        $.messager.confirm('删除确认','确认是否删除',function (r){
            if(r) {
                var selectedObj = $("#resourceList").datagrid("getSelected");
                if(Kit.isEmpty(selectedObj)) {
                    $.messager.alert("帮助提示","请选中要删除的行");
                    return false;
                }

                ui.request({
                    url:"/admin/resource/delete",
                    data:{"id":selectedObj.id},
                    success:function (rtn) {
                        if(rtn.code != undefined && rtn.code !== "0000"){
                            $.messager.alert(rtn.msg,rtn.desc);
                        }
                        $("#resourceList").datagrid("reload",{});
                    }
                })
            }
        });
    })
}

